<?xml version="1.0" encoding="IBM437"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta content="text/html; charset=IBM437" http-equiv="Content-Type" />

  <title>Class: Inline::VBScript</title>

  <link rel="stylesheet" href="../rdoc.css" type="text/css" media="screen" />

  <script src="../js/jquery.js" type="text/javascript" charset="utf-8"></script>
  <script src="../js/thickbox-compressed.js" type="text/javascript" charset="utf-8"></script>
  <script src="../js/quicksearch.js" type="text/javascript" charset="utf-8"></script>
  <script src="../js/darkfish.js" type="text/javascript" charset="utf-8"></script>

</head>
<body id="top" class="class">

  <div id="metadata">
    <div id="home-metadata">
      <div id="home-section" class="section">
        <h3 class="section-header">
          <a href="../index.html">Home</a>
          <a href="../index.html#classes">Classes</a>
          <a href="../index.html#methods">Methods</a>
        </h3>
      </div>
    </div>

    <div id="file-metadata">
      <div id="file-list-section" class="section">
        <h3 class="section-header">In Files</h3>
        <div class="section-body">
          <ul>
          
            <li><a href="../lib/rub_a_scripts_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
              class="thickbox" title="lib/rub_a_scripts.rb">lib/rub_a_scripts.rb</a></li>
          
          </ul>
        </div>
      </div>

      
    </div>

    <div id="class-metadata">
      
      <!-- Parent Class -->
      <div id="parent-class-section" class="section">
        <h3 class="section-header">Parent</h3>
        
        <p class="link">Object</p>
        
      </div>
      

      

      

      
      <!-- Method Quickref -->
      <div id="method-list-section" class="section">
        <h3 class="section-header">Methods</h3>
        <ul class="link-list">
          
          <li><a href="#method-c-new">::new</a></li>
          
          <li><a href="#method-i-build">#build</a></li>
          
          <li><a href="#method-i-clear_inline_folder">#clear_inline_folder</a></li>
          
          <li><a href="#method-i-extra_input_fx">#extra_input_fx</a></li>
          
          <li><a href="#method-i-load">#load</a></li>
          
          <li><a href="#method-i-load_cache">#load_cache</a></li>
          
          <li><a href="#method-i-vbscript">#vbscript</a></li>
          
        </ul>
      </div>
      

      
    </div>

    <div id="project-metadata">
      
      
      <div id="fileindex-section" class="section project-section">
        <h3 class="section-header">Files</h3>
        <ul>
        
          <li class="file"><a href="../License_txt.html">License.txt</a></li>
        
          <li class="file"><a href="../README_txt.html">README.txt</a></li>
        
          <li class="file"><a href="../Rakefile.html">Rakefile</a></li>
        
          <li class="file"><a href="../bin/rub_a_scripts.html">rub_a_scripts</a></li>
        
        </ul>
      </div>
      

      <div id="classindex-section" class="section project-section">
        <h3 class="section-header">Class/Module Index
          <span class="search-toggle"><img src="../images/find.png"
            height="16" width="16" alt="[+]"
            title="show/hide quicksearch" /></span></h3>
        <form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
        <fieldset>
          <legend>Quicksearch</legend>
          <input type="text" name="quicksearch" value=""
            class="quicksearch-field" />
        </fieldset>
        </form>

        <ul class="link-list">
        
          <li><a href="../Inline.html">Inline</a></li>
        
          <li><a href="../Inline/VBScript.html">Inline::VBScript</a></li>
        
          <li><a href="../MyVBScriptClass.html">MyVBScriptClass</a></li>
        
          <li><a href="../TestRubAScript.html">TestRubAScript</a></li>
        
        </ul>
        <div id="no-class-search-results" style="display: none;">No matching classes.</div>
      </div>

      
    </div>
  </div>

  <div id="documentation">
    <h1 class="class">Inline::VBScript</h1>

    <div id="description" class="description">
      
<p><a href="VBScript.html">VBScript</a> <a href="../Inline.html">Inline</a> -
allow simple inline of <a href="VBScript.html">VBScript</a> within Ruby.</p>

    </div><!-- description -->

    
    
    
    <div id="5Buntitled-5D" class="documentation-section">
      

      

      

      
      <!-- Attributes -->
      <div id="attribute-method-details" class="method-section section">
        <h3 class="section-header">Attributes</h3>

        
        <div id="extra_args-attribute-method" class="method-detail">
          <a name="extra_args"></a>
          
          <a name="extra_args="></a>
          
          <div class="method-heading attribute-method-heading">
            <span class="method-name">extra_args</span><span
              class="attribute-access-type">[RW]</span>
          </div>

          <div class="method-description">
          
          <p><a href="VBScript.html#attribute-i-extra_args">extra_args</a>: Allow the
user to specify any other arguments they want to add. By default //Nologo
is added.</p>
          
          </div>
        </div>
        
      </div><!-- attribute-method-details -->
      

      <!-- Methods -->
      
      <div id="public-class-method-details" class="method-section section">
        <h3 class="section-header">Public Class Methods</h3>

      
        <div id="new-method" class="method-detail ">
          <a name="method-c-new"></a>

          
          <div class="method-heading">
            <span class="method-name">new</span><span
              class="method-args">(mod)</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            
            

            
            <div class="method-source-code" id="new-source">
<pre>
<span class="ruby-comment"># File lib/rub_a_scripts.rb, line 15</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">mod</span>)
  <span class="ruby-ivar">@context</span> = <span class="ruby-identifier">mod</span>
  <span class="ruby-ivar">@src</span> = <span class="ruby-string">&quot;&quot;</span>
  <span class="ruby-ivar">@imports</span> = []
  <span class="ruby-ivar">@sigs</span> = []
  <span class="ruby-ivar">@file_name</span> = <span class="ruby-string">''</span>
  <span class="ruby-ivar">@extra_args</span> = <span class="ruby-string">'//Nologo'</span>
<span class="ruby-keyword">end</span></pre>
            </div><!-- new-source -->
            
          </div>

          

          
        </div><!-- new-method -->

      
      </div><!-- public-class-method-details -->
    
      <div id="public-instance-method-details" class="method-section section">
        <h3 class="section-header">Public Instance Methods</h3>

      
        <div id="build-method" class="method-detail ">
          <a name="method-i-build"></a>

          
          <div class="method-heading">
            <span class="method-name">build</span><span
              class="method-args">()</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            <p>@build. Build source <a href="VBScript.html">VBScript</a> file to be later
used for execution.</p>

<pre>- grabbing all your vbscript source code
- creating a vbscript file and then inputing in the code
- it will also add an extra vbscript function that will
later be called to pass in parameters and output result to
a file so Ruby can pick up.</pre>
            

            
            <div class="method-source-code" id="build-source">
<pre>
<span class="ruby-comment"># File lib/rub_a_scripts.rb, line 71</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">build</span>
  <span class="ruby-ivar">@load_name</span> = <span class="ruby-ivar">@name</span> = <span class="ruby-node">&quot;VBScript#{@src.hash.abs}&quot;</span>
  <span class="ruby-ivar">@file_name</span> = <span class="ruby-node">&quot;#{Inline.directory}/#{@name}.vbs&quot;</span>
  <span class="ruby-ivar">@src</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">extra_input_fx</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&quot;\n&quot;</span>
  <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-ivar">@file_name</span>, <span class="ruby-string">'w'</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">file</span><span class="ruby-operator">|</span> <span class="ruby-identifier">file</span>.<span class="ruby-identifier">write</span>(<span class="ruby-ivar">@src</span>)}
<span class="ruby-keyword">end</span></pre>
            </div><!-- build-source -->
            
          </div>

          

          
        </div><!-- build-method -->

      
        <div id="clear_inline_folder-method" class="method-detail ">
          <a name="method-i-clear_inline_folder"></a>

          
          <div class="method-heading">
            <span class="method-name">clear_inline_folder</span><span
              class="method-args">()</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            <p>This method will clear out the inline directory if any files is more than 3
days old.</p>
            

            
            <div class="method-source-code" id="clear_inline_folder-source">
<pre>
<span class="ruby-comment"># File lib/rub_a_scripts.rb, line 38</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">clear_inline_folder</span>
  <span class="ruby-identifier">files</span> = <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">glob</span>(<span class="ruby-node">&quot;#{Inline.directory}/VBScript*&quot;</span>)
  <span class="ruby-identifier">files</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">file</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">file_time</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">ctime</span>(<span class="ruby-identifier">file</span>)
    <span class="ruby-identifier">today_date</span> = <span class="ruby-constant">Date</span>.<span class="ruby-identifier">today</span>
    <span class="ruby-keyword">if</span> ((<span class="ruby-identifier">file_time</span>.<span class="ruby-identifier">day</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">today_date</span>.<span class="ruby-identifier">day</span>) <span class="ruby-operator">&gt;=</span> <span class="ruby-value">2</span>) <span class="ruby-keyword">and</span> (<span class="ruby-identifier">file_time</span>.<span class="ruby-identifier">month</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-identifier">today_date</span>.<span class="ruby-identifier">month</span>) <span class="ruby-keyword">and</span> (<span class="ruby-identifier">file_time</span>.<span class="ruby-identifier">year</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-identifier">today_date</span>.<span class="ruby-identifier">year</span>)
      <span class="ruby-constant">FileUtils</span>.<span class="ruby-identifier">rm_rf</span>(<span class="ruby-identifier">file</span>)
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
            </div><!-- clear_inline_folder-source -->
            
          </div>

          

          
        </div><!-- clear_inline_folder-method -->

      
        <div id="extra_input_fx-method" class="method-detail ">
          <a name="method-i-extra_input_fx"></a>

          
          <div class="method-heading">
            <span class="method-name">extra_input_fx</span><span
              class="method-args">()</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            <p>The inside man. This source code and methods is added and inject into the
<a href="VBScript.html">VBScript</a>.</p>

<pre>It's responsible for picking up arguments and executing the VBScript function
being called. Will also write result to stdout so that Ruby can pick up.
A few basic mapping and error handling is also being done here vs the load method on the Ruby side.</pre>
            

            
            <div class="method-source-code" id="extra_input_fx-source">
<pre>
<span class="ruby-comment"># File lib/rub_a_scripts.rb, line 173</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">extra_input_fx</span>()
  <span class="ruby-identifier">my_str1</span> = <span class="ruby-string">'
  Function fxWriteOutput
                InputArgs = WScript.Arguments.Item(0)
    InputArgs = Replace(InputArgs, &quot;\&quot;, chr(34))
          if WScript.Arguments.Count() &gt; 0 Then
      On Error Resume Next
        fx_value = Eval(InputArgs)
        If Err.Number &lt;&gt; 0 Then
          If Err.Description = &quot;Object doesn\t support this property or method&quot; Then
            fx_value = &quot;Error: &quot; &amp; Err.Description &amp; &quot;. Sorry!!! Object are not mapped.&quot;
          End If
          Err.Clear
        End If
      On Error Goto 0
      '</span> <span class="ruby-operator">+</span> <span class="ruby-string">&quot;\n&quot;</span>
  <span class="ruby-identifier">my_str_3</span> = <span class="ruby-string">'
        if IsArray(fx_value) = False Then
          if fx_value = True Then
            WScript.Echo &quot;True&quot;
          elseif IsEmpty(fx_value) Then
            WScript.Echo &quot;Empty&quot;
          elseif fx_value = False Then
            WScript.Echo &quot;False&quot;
          else
            WScript.Echo fx_value
          End If
        else
          my_array_list = &quot;Array&quot; &amp; abcExpandArray(fx_value)
          WScript.Echo my_array_list
        End if
    End if
  End Function
  fxWriteOutput()

  Function abcExpandArray(fx_value)
          If IsArray(fx_value) Then
      For i = (lbound(fx_value)) to ubound(fx_value)
        if i &gt; 0 Then
          finalStr = finalStr &amp; &quot;,&quot; &amp; abcExpandArray(fx_value(i))
        Else
          finalStr = finalStr &amp; abcExpandArray(fx_value(i))
        End If
      Next
      abcExpandArray = &quot;[&quot; &amp; finalStr  &amp; &quot;]&quot;
    Else
      If IsNumeric(fx_value) Then
        abcExpandArray = fx_value
      ElseIf fx_value = True Then
        abcExpandArray =  &quot;True&quot;
      ElseIf IsEmpty(fx_value) Then
        abcExpandArray =  &quot;Empty&quot;
      ElseIf fx_value = False Then
        abcExpandArray =  &quot;False&quot;
      Else
        abcExpandArray = &quot;&quot;&quot;&quot; &amp; fx_value &amp; &quot;&quot;&quot;&quot;
      End If
          End If
  End Function
  '</span>
  <span class="ruby-keyword">return</span> (<span class="ruby-identifier">my_str1</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">my_str_3</span>)
<span class="ruby-keyword">end</span></pre>
            </div><!-- extra_input_fx-source -->
            
          </div>

          

          
        </div><!-- extra_input_fx-method -->

      
        <div id="load-method" class="method-detail ">
          <a name="method-i-load"></a>

          
          <div class="method-heading">
            <span class="method-name">load</span><span
              class="method-args">()</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            <p>This method is used to dynamically create all the Ruby methods</p>

<pre>that is associate with their VBScript methods. No doubt the
most important method of this module as it's reponsible for
creating handling interactions between Ruby and VBScript.</pre>
            

            
            <div class="method-source-code" id="load-source">
<pre>
<span class="ruby-comment"># File lib/rub_a_scripts.rb, line 84</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">load</span>
  <span class="ruby-ivar">@context</span>.<span class="ruby-identifier">module_eval</span> <span class="ruby-node">&quot;const_set :#{@name}, Inline::VBScript;&quot;</span>

  <span class="ruby-ivar">@context</span>.<span class="ruby-identifier">module_eval</span> <span class="ruby-node">&quot;
  def clean_cache
    files = Dir.glob(\&quot;\#{Inline.directory}/VBScript*\&quot;)
    files.each {|file| FileUtils.rm_rf(file)}
  end
  def delete_file
    File.delete('#{@file_name}') if File.exist?('#{@file_name}');
  end
  &quot;</span>

  <span class="ruby-ivar">@context</span>.<span class="ruby-identifier">module_eval</span> <span class="ruby-string">&quot;
  def construct_arguments(*args)
    @argument_to_send = ''
    if args.class == Array
      args.each_with_index do |top_level_item, args_index|
        @argument_to_send += \&quot;,\&quot; if args_index &gt; 0
        if top_level_item.class == Array
          @argument_to_send += \&quot;Array(\&quot;
          top_level_item.each_with_index do |inner_item, top_level_index|
            @argument_to_send += \&quot;,\&quot; if top_level_item.count != top_level_index and top_level_index &gt; 0
            @argument_to_send += construct_arguments(inner_item)
          end
          @argument_to_send += \&quot;)\&quot;
        else
          case
            when top_level_item.class == String
              @argument_to_send += %q[\&quot;] + %Q[\#{top_level_item.to_s}] + %q[\&quot;]
            when top_level_item.class == Fixnum
              @argument_to_send += top_level_item.to_s
            when top_level_item.class == TrueClass
              @argument_to_send += \&quot;True\&quot;
            when top_level_item.class == FalseClass
              @argument_to_send += \&quot;False\&quot;
            else
              @argument_to_send += top_level_item.to_s
          end
        end
      end
    end
    return @argument_to_send
  end
  &quot;</span>

  <span class="ruby-ivar">@sigs</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">sig</span><span class="ruby-operator">|</span>
    <span class="ruby-ivar">@context</span>.<span class="ruby-identifier">module_eval</span> <span class="ruby-node">&quot;
    def #{sig[0]}(*args);
      @arguments_to_send = construct_arguments(args)
      @arguments_to_send.sub!(\&quot;Array(\&quot;,\&quot;\&quot;).chomp!(\&quot;)\&quot;)
      @arguments_to_send.gsub!(/\&quot;/, \'\\'\')
      @arguments_to_send.chomp!
      execution_str = 'cscript #{@file_name} \&quot;#{sig[0]}' + '(' + @arguments_to_send + ')\&quot; #{@extra_args}';

      IO.popen(execution_str).each do |line|
        case
          when (line.strip == \&quot;nothing\&quot; or line.strip == \&quot;null\&quot; or line.strip == \&quot;Empty\&quot;)
            @result = nil
          when line.strip == \&quot;False\&quot;
            @result = false
          when line.strip == \&quot;True\&quot;
            @result = true
          when line.strip[/^[-+]?[0-9]+$/]
            @result = line.strip.to_i
          when line.strip[/^[-+]?[\\d]+(\\.[\\d]+){0,1}$/]
            @result = line.strip.to_f
          when line.strip[/Array\\[.*\\]/]
            begin
              @result = eval(line.strip.gsub(\&quot;Array\&quot;,\&quot;\&quot;).gsub(\&quot;True\&quot;,\&quot;true\&quot;).gsub(\&quot;False\&quot;,\&quot;false\&quot;))
            rescue =&gt; e
              @result = line.strip;
              warn(e)
            end
          else
            @result = line.strip;
        end
      end.close
      return @result
    end&quot;</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
            </div><!-- load-source -->
            
          </div>

          

          
        </div><!-- load-method -->

      
        <div id="load_cache-method" class="method-detail ">
          <a name="method-i-load_cache"></a>

          
          <div class="method-heading">
            <span class="method-name">load_cache</span><span
              class="method-args">()</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            <p>Use by RubyInline to designate new file or to reuse cache. For <a
href="VBScript.html">VBScript</a></p>

<pre>we simply create a new file every times so this will always be set to false.
Also crapped in here a method to clear out the inline folder if files are
more than 3 days old.</pre>
            

            
            <div class="method-source-code" id="load_cache-source">
<pre>
<span class="ruby-comment"># File lib/rub_a_scripts.rb, line 30</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">load_cache</span>
  <span class="ruby-identifier">clear_inline_folder</span>
  <span class="ruby-keyword">false</span>
<span class="ruby-keyword">end</span></pre>
            </div><!-- load_cache-source -->
            
          </div>

          

          
        </div><!-- load_cache-method -->

      
        <div id="vbscript-method" class="method-detail ">
          <a name="method-i-vbscript"></a>

          
          <div class="method-heading">
            <span class="method-name">vbscript</span><span
              class="method-args">(src)</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            <p>Parse your <a href="VBScript.html">VBScript</a> to find a function name.
Store them sor Ruby</p>

<pre>can create a Ruby method with the exact name and parameters list.</pre>
            

            
            <div class="method-source-code" id="vbscript-source">
<pre>
<span class="ruby-comment"># File lib/rub_a_scripts.rb, line 53</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">vbscript</span>(<span class="ruby-identifier">src</span>)
  <span class="ruby-ivar">@src</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">src</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&quot;\n&quot;</span>
  <span class="ruby-identifier">signature</span> = <span class="ruby-identifier">src</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp">/Function\W+([a-zA-Z0-9_]+)\((.*)\)/</span>)
  <span class="ruby-ivar">@sigs</span> <span class="ruby-operator">&lt;&lt;</span> [<span class="ruby-identifier">signature</span>[<span class="ruby-value">1</span>], <span class="ruby-identifier">signature</span>[<span class="ruby-value">2</span>], <span class="ruby-identifier">signature</span>[<span class="ruby-value">3</span>]] <span class="ruby-keyword">unless</span> <span class="ruby-operator">!</span><span class="ruby-identifier">signature</span>
  <span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">signature</span>
    <span class="ruby-identifier">signature</span> = <span class="ruby-identifier">src</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp">/Sub\W+([a-zA-Z0-9_]+)\((.*)\)/</span>)
    <span class="ruby-ivar">@sigs</span> <span class="ruby-operator">&lt;&lt;</span> [<span class="ruby-identifier">signature</span>[<span class="ruby-value">1</span>], <span class="ruby-identifier">signature</span>[<span class="ruby-value">2</span>], <span class="ruby-identifier">signature</span>[<span class="ruby-value">3</span>]] <span class="ruby-keyword">unless</span> <span class="ruby-operator">!</span><span class="ruby-identifier">signature</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
            </div><!-- vbscript-source -->
            
          </div>

          

          
        </div><!-- vbscript-method -->

      
      </div><!-- public-instance-method-details -->
    
    </div><!-- 5Buntitled-5D -->
  

  </div><!-- documentation -->

  <div id="validator-badges">
    <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
    <p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
      Rdoc Generator</a> 2</small>.</p>
  </div>

</body>
</html>

